'use strict';
const db = uniCloud.database()
const collection = db.collection('order')
exports.main = (event, context) => {
	console.log("事件：", event.id);
	switch(event.type) {
		case 'notPay': 
			return notOrder(event.info)
		case 'waitFa':
			return waitFaHuo(event.info)
		case 'getAll':
			return getAllOrder()
		case 'delete1': 
			return delete1(event.id)
	}
};

//待付款
async function notOrder(info) {
	const res = await collection.add(info)
	return res
}

//待发货
async function waitFaHuo(info) {
	const res = await collection.add(info)
	return res
}

//得到所有的信息
async function getAllOrder() {
	const res = await collection.get()
	return res
}

//删除订单
async function delete1(id) {
	
	const res = await collection.doc(id).remove()
	return res
}